package com.xm.servlet.background.administrator;

import com.google.gson.Gson;
import com.xm.entity.Administrator;
import com.xm.service.background.AdministratorService;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 账号Servlet
 *
 * @author 陈盼
 * @date 2023-01-11 上午 10：00
 */
@WebServlet("/background/add/administrator")
public class AddAdministratorServlet extends HttpServlet {
    private final AdministratorService service = new AdministratorService();

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String administrator = req.getParameter("administrator");
        System.out.println(new Gson().fromJson(administrator, Administrator.class));
        resp.getWriter().print(service.addAdministrator(new Gson().fromJson(administrator, Administrator.class)));
    }
}
